package com.ruoyi.ruoyiserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ruoyiserver.domain.PeDataInformation;
import com.ruoyi.ruoyiserver.domain.PeRecord;
import com.ruoyi.ruoyiserver.mapper.PeRecordMapper;
import com.ruoyi.ruoyiserver.service.PeRecordService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

import static com.ruoyi.common.utils.PageUtils.startPage;

@RestController
@RequestMapping("/person/record")
@Api(tags = "查询日志")
public class PeRecordController extends BaseController {
    @Autowired
    private PeRecordService peRecordService;
    @Autowired
    private PeRecordMapper peRecordMapper;
    /*查询*/
    @GetMapping("/list")
    public TableDataInfo list(PeRecord peRecord)
    {
        startPage();
        List<PeRecord> list = peRecordService.selectPeDataInformationList(peRecord);
        if (null != peRecord.getStartTime() && null != peRecord.getEndTime()){
            List<PeRecord> filteredList = list.stream().filter(record -> record.getCreateTime().after(peRecord.getStartTime())
                    && record.getCreateTime().before(peRecord.getEndTime())).collect(Collectors.toList());
            return getDataTable(filteredList);
        }
        return getDataTable(list);
    }

    /*增加*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PeRecord peRecord)
    {
        return toAjax(peRecordMapper.insert(peRecord));
    }

    /*修改*/
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PutMapping
    public AjaxResult edit(@RequestBody PeRecord peDataInformation)
    {
        return toAjax(peRecordMapper.updateById(peDataInformation));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(peRecordMapper.deleteBatchIds(Arrays.asList(ids)));
    }
}
